/**
 * CommandThread.java
 * 2009-4-29 下午02:57:51
 *
 */
package com.esen.auwserv;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author 何江舟
 *
 */
public class CommandThread implements Runnable {

  private String command; // 用户输入的命令

  /**
   * 创建一个默认的CommandThread对象，将command实例变量设置为null
   */
  public CommandThread() {
    command = null;
  }

  public CommandThread(String command) {
    this.command = command;
  }

  public void run() {
    enterCommand();
    if ("exit".equalsIgnoreCase(command)) {
      doExit();
    }
  }

  private void enterCommand() {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    try {
      if (reader != null) {
        command = reader.readLine();
      }
    }
    catch (IOException ioe) {
      ioe.printStackTrace();
    }
    finally {
      if (reader != null) {
        try {
          reader.close();
        }
        catch (IOException ioe) {
          ioe.printStackTrace();
        }
      }
    }
  }

  // 响应用户exit命令的方法
  private void doExit() {
    System.exit(0);
  }
}
